package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.CheckHabitusMapper;
import com.hu.zhcc.shiro.dao.CheckMindMapper;
import com.hu.zhcc.shiro.dao.CheckResultMapper;
import com.hu.zhcc.shiro.entity.bo.CheckHabitus;
import com.hu.zhcc.shiro.entity.bo.CheckMind;
import com.hu.zhcc.shiro.entity.bo.CheckResult;
import com.hu.zhcc.shiro.entity.vo.CheckHabitusVO;
import com.hu.zhcc.shiro.entity.vo.CheckMindVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckMindServiceImpl implements CheckMindService{

    @Autowired
    private CheckMindMapper checkMindMapper;

    @Override
    public boolean AddMind(CheckMind checkMind) {
        if(checkMind.getFilenumber()=="" || checkMind.getFilenumber()==null ||checkMind.getFilenumber().length()==0){
            checkMindMapper.insertSelective(checkMind);
            CheckMind habitus = checkMindMapper.selectByPrimaryKey(checkMind.getId());
            String  valuationdate = habitus.getValuationdate();
            String[] strings = valuationdate.split("-");
            String newnumber=strings[0]+strings[1]+strings[2]+"00"+checkMind.getId();
            habitus.setFilenumber(newnumber);
            return checkMindMapper.updateByPrimaryKey(habitus)>0;
        }else {
            return checkMindMapper.insert(checkMind)>0;
        }
    }
    //分页查询
    @Override
    public PageInfo<CheckMind> pageQuery(CheckMindVO checkMindVO) {
        PageHelper.startPage(checkMindVO.getPageNum(),checkMindVO.getPageSize());
        List<CheckMind> byCondition = checkMindMapper.findByCondition(checkMindVO.getQueryString());
        PageInfo<CheckMind> checkItemPageInfo = new PageInfo<>(byCondition);
        return checkItemPageInfo;
    }

    @Override
    public boolean updateMind(CheckMind checkMind) {
        return checkMindMapper.updateByPrimaryKey(checkMind)>0;
    }

    @Override
    public boolean removeMind(Short id) {
        return checkMindMapper.deleteByPrimaryKey(id)>0;
    }
}
